package com.yjt.admin.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yjt.admin.system.entity.HandOver;
import com.yjt.admin.system.form.HandOverForm;
import com.yjt.admin.system.param.HandOverParam;
import com.yjt.admin.system.service.HandOverService;
import com.yjt.admin.system.vo.HandOverVO;
import com.yjt.common.enums.ModulEnum;
import com.yjt.common.enums.OperTypeEnum;
import com.yjt.common.log.annotation.OperLog;
import com.yjt.common.vo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 工作交接表 前端控制器
 * </p>
 *
 * @author zzp
 * @since 2021-10-13
 */
@RefreshScope // 支持Nacos的动态刷新功能
@RestController
@RequestMapping("/admin/system/hand-over")
@Api(tags = "工作交接管理")
public class HandOverController {

    @Autowired
    private HandOverService handOverService;

    @PostMapping("/add")
    @ApiOperation(value = "增加工作交接信息", notes = "返回JSONObject")
    @OperLog(operModul = ModulEnum.HAND_OVER_MODUL, operType = OperTypeEnum.ADD, operDesc = "新增工作交接信息")
    public CommonResult addHandOver(@RequestBody HandOverForm handOverForm) {
        HandOver handOver = new HandOver();
        BeanUtils.copyProperties(handOverForm, handOver);
        handOverService.save(handOver);
        return CommonResult.success("工作交接新增成功");
    }


    @DeleteMapping("/delete")
    @ApiOperation(value = "删除工作交接信息", notes = "返回JSONObject")
    @ApiImplicitParam(name = "handOverId", value = "工作交接id")
    @OperLog(operModul = ModulEnum.HAND_OVER_MODUL, operType = OperTypeEnum.DEL, operDesc = "删除工作交接信息")
    public CommonResult delHandOver(String handOverId) {
        handOverService.removeById(handOverId);
        return CommonResult.success("工作交接删除成功");
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改工作交接信息", notes = "返回JSONObject")
    @OperLog(operModul = ModulEnum.HAND_OVER_MODUL, operType = OperTypeEnum.MOD, operDesc = "修改工作交接信息")
    public CommonResult updateHandOver(@RequestBody HandOverForm handOverForm) {
        HandOver handOver = new HandOver();
        BeanUtils.copyProperties(handOverForm, handOver);
        handOverService.updateById(handOver);
        return CommonResult.success("工作交接修改成功");
    }

    @GetMapping("/{handOverId}")
    @ApiOperation(value = "查询工作交接信息", notes = "返回JSONObject")
    @ApiImplicitParam(name = "handOverId", value = "工作交接id")
    public CommonResult<HandOverVO> getOneHandOver(@PathVariable String handOverId) {
        return CommonResult.success(handOverService.getOneHandOver(handOverId), "工作交接信息查询成功");
    }


    @PostMapping("/list-page")
    @ApiOperation(value = "查询分页工作交接信息", notes = "返回JSONObject")
    public CommonResult<IPage<HandOverVO>> getPageHandOver(@RequestBody HandOverParam handOverParam) {
        return CommonResult.success(handOverService.getPageHandOver(handOverParam), "查询工作交接分页信息成功");
    }


}
